//
//  Activity.swift
//  zpzk_shop
//
//  Created by Qingke on 16/5/19.
//  Copyright © 2016年 Qingke. All rights reserved.
//

import Foundation
import UIKit
class Activity {
    var url: String?
    var imageUrl: String?
    var name: String?
    var image_path: String? //scorllView的图片的URL地址
    
    class func saveData(data: AnyObject?) -> [Activity] {
        let activities = data!["activities"] as! [[String:AnyObject]]
        var returnData = [Activity]()
        for activityData in activities {
            let activity = Activity()
            activity.url = activityData["url"] as? String
            activity.image_path = activityData["image_path"] as? String

            activity.imageUrl = activityData["image_url"] as? String
            returnData.append(activity)
        }
        return returnData
    }
    class func loadData(viewcontroller: HomePageViewController) {
        var param = [String: AnyObject]()
        param["client_type"] = "iphone"
        param["num"] = "4"
        param["pa"] = "pa"
        HttpManager.httpGetRequest(.GET, url: "http://api.zpzk100.com/client/brand_theme_index", params: param, onSucess: { (sucessDate) in
            //相应的赋值 并且save
            
            viewcontroller.activities = self.saveData(sucessDate)
            viewcontroller.loadScrollView()
            viewcontroller.activitiesShop = ActivityShop.getActivityShop(sucessDate)
            viewcontroller.shopTableView.reloadData()
//            print("save Data:" + "\(data[0].imageUrl)")
            }) { (failedDate) in
        }
    }
}